package org.jivesoftware.spark.crowd;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import javax.swing.ImageIcon;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.spark.SessionManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatContainer;
/**
 * 
 * @author liyuan
 *
 */
public class Param {
	private static Calendar cld = new GregorianCalendar();
	private static Map<String,String> labelText = new HashMap<String,String>();
	static{
		labelText.put("createCrowd", "创建一个新群");
		labelText.put("searchCrowd", "查找群");
		labelText.put("crowdChat", "发送群消息");
		labelText.put("singleChat", "发送消息");
		labelText.put("removeMember", "移除成员");
		
		
		
	}
	/**
	 * 
	 */
	public static final String CROWD_SERVICE_NAME = "crowd";
	/**
	 * 
	 */
	public static final String discoLocalCrowds_NS = "http://www.cecise.com/ceciseim/disco/locals";

	/**
	 * 
	 */
	public static final String discoCrowdMembers_NS = "http://www.cecise.com/ceciseim/disco/members";
	/**
	 * 
	 */
	public static final String create_NS = "http://www.cecise.com/ceciseim/new";
	/**
	 * 
	 */
	public static final String quit_NS = "http://www.cecise.com/ceciseim/quit";
	/**
	 * 
	 */
	public static final String destroy_NS = "http://www.cecise.com/ceciseim/destroy";
	/**
	 * 
	 */
	public static final String search_NS = "http://www.cecise.com/ceciseim/search";
	
	/**
	 * reply for an apply
	 */
	public static final String apply_NS = "http://www.cecise.com/ceciseim/apply";
	/**
	 * reply for an invite
	 */
	public static final String invite_NS = "http://www.cecise.com/ceciseim/invite";
	/**
	 * 
	 */
	public static final String message_NS = "http://www.cecise.com/ceciseim/message";
	/**
	 * 
	 */
	public static final String serviceName = SparkManager.getConnection().getServiceName();
	/**
	 * 
	 */
	public static final String uploadPath = "http://"+SparkManager.getConnection().getHost()+":9090/servlet/crowd";
	
	
	/**
	 * 
	 * @return
	 */
	public static String getUserJID(){		
		return SparkManager.getSessionManager().getJID();
	}
	
	
	/**
	 * 
	 * @return
	 */
	public static String getBareAddress(){
		return SparkManager.getSessionManager().getBareAddress();
	}
	public static String getSparkVersion(){
		return "1.0";
	}
	public static String getFullCrowdDomain(){
		return CROWD_SERVICE_NAME + "." + SparkManager.getConnection().getServiceName();
	}
	public static Connection getConnection(){
		return SparkManager.getConnection();
	}
	public static String getUserName(){
		return SparkManager.getSessionManager().getUsername();
	}
	public static ChatContainer getChatContainer(){
		return SparkManager.getChatManager().getChatContainer();
	}
	
	public static String getLabelText(String name,String dfut){
		
		return labelText.get(name) == null?dfut:labelText.get(name);
	}


	public static String getNickName() {	
		return SparkManager.getUserManager().getNickname();
	}
	
	public static ImageIcon getCrowdIcon(){
		return SparkRes.getImageIcon(SparkRes.RED_FLAG_16x16);
	}
	public static SessionManager getSessionManager(){
		return SparkManager.getSessionManager();
	}
	public static String getNickNameFromJID(String jid){
		return SparkManager.getUserManager().getNickname(jid);
	}
	public static String getFullJID(){
		return SparkManager.getSessionManager().getJID();
	}
	public static String parseTime(long millis){
		cld.setTimeInMillis(millis);
		return cld.get(Calendar.YEAR) + "/" + (cld.get(Calendar.MONTH)+1) + "/" + cld.get(Calendar.DAY_OF_MONTH);
	}


	public static String getUnavailableIcon() {
		// TODO Auto-generated method stub
		return SparkRes.IM_UNAVAILABLE_STALE_IMAGE;
	}
}
